<?php
require_once ('TConfig.php');
/**
 * Description of TConexao
 *
 * @author Roberto
 */
class TConexao extends PDO {
 
    private static $_instance;
        
    public function __construct() {
        parent::__construct(DSN, USERNAME, PASSWORD);
    } 
    
    public function getConnection(){
         if(!self::$_instance){
            try {
                self::$_instance = new PDO(DSN,USERNAME,PASSWORD);
                self::$_instance->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND,"SET NAMES utf8; SET CHARACTER SET utf8");
                self::$_instance->setAttribute(PDO::ATTR_PERSISTENT, true);
                self::$_instance->setAttribute(PDO::ATTR_AUTOCOMMIT,false);
                self::$_instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            }
            catch(PDOException $est) {
                die("Erro na conexão PDO ". $est->getMessage() ."<br/>");
            }
        }
        return self::$_instance;
    }
 
    public function __destruct() {
        self::$_instance = null;
    }

}

?>

